<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let str = '1.txt';

        if (str.endsWith('.txt')) {
            alert('文本文件');
        } else if (str.endsWith('jpg')) {
            alert('JPG图片');
        } else {
            alert('其他')
        }
    </script>
</body>
</html>